package comlanka.appengine.property;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: ishara
 * Date: 9/3/11
 * Time: 10:17 AM
 * To change this template use File | Settings | File Templates.
 */
public class ASP {
    static {
        ObjectifyService.register(Property.class);
    }

    public static List<Property> getProperty()
    {
        Objectify ofy = ObjectifyService.begin();
        return ofy.query(Property.class).list();
    }
    public static Property getProperty(String code)
    {
       Objectify ofy = ObjectifyService.begin();
       return ofy.query(Property.class).filter("code", code).get();
    }
    public static void setPropertyValue(String code,String value) {
        Objectify ofy = ObjectifyService.begin();
        Property property = getProperty(code);
        if (property == null) {
            Property newProperty = new Property(code, value);
            ofy.put(newProperty);
        }
        else {
            property.setValue(value);
            ofy.put(property);
        }
    }

}
